<?php
namespace App\Services\Fund\CurrencyFreezeLog;
use App\Services\Fund\ValidateCurrencyFreezeLog;
use App\Models\Fund\CurrencyFreezeLog;
use Illuminate\Support\Facades\DB;
class CurrencyFreezeLogLogic
{
    // 所有用户数字币冻结日志分页数据
    public function list(array $data): array
    {
        $query = CurrencyFreezeLog::where('status','=',1);
        $data['keywords'] != '' && $query->where('user_id','like',"%{data['keywords']}%");
        $data['type'] != '' && $query->where('type','=',$data['type']);
        if($data['startTime'] != ''){
            if($data['endTime'] != ''){
                $query->whereBetween('create_time', [$data['startTime'], $data['endTime']]);
            }else{
               $query->where('create_time','>=',$data['startTime']); 
            }
        }else{
            $data['endTime'] != '' &&  $query->where('create_time','<=',$data['endTime']);
        } 
         $res = $query->orderBy('id', 'desc')
                      ->paginate($data['list_rows'], null, null, $data['page'])
                      ->toArray();
        return auto_return_page($res, '已找到用户数字币冻结日志', '没有用户数字币冻结日志');
    }
    // 获取某些user_ids的的数字币冻结日志(分页)
    public function listByUserIds(array $data): array
    {
        $where['status'] = 1;
        $res = CurrencyFreezeLog::where($where)
                     ->whereIn('user_id',[$data['user_ids']])
                     ->orderBy('id', 'desc')
                     ->paginate($data['list_rows'], null, null, $data['page'])
                     ->toArray();
        return auto_return_page($res, '已找到用户数字币冻结日志', '没有用户数字币冻结日志');
    }

    //获取某一条数字币冻结日志
    public function getOneInfo($data): array 
    {
        $_where['user_id'] = $data['user_id'];
        //注释47行的原因： 
        //在艺货app_id中用户A转让给用户B一个证书（在艺货中冻结A），但用户B可以在亚数app_id中同意（在亚数中解冻A），故限制app_id会找不到冻结日志记录
        //$_where['app_id'] = $data['app_id'];
        $_where['type'] = $data['type'];
        $_where['obj_id'] = $data['obj_id'];
        $_where['freeze_counts'] = $data['freeze_counts'];
        $_where['freeze_status'] = $data['freeze_status'];
        $_where['status'] = 1;

        $res =CurrencyFreezeLog::where($_where)->first();
        return auto_return($res);
    }
}